package com.summer.Collection.msb;

import java.util.Iterator;
import java.util.LinkedList;

public class Test03 {
    public static void main(String[] args) {
        //LinkedList常用方法
        //增加
        //addFirst() addLast() offer() offerFirst() offerLast()
        //删除
        //poll() pollFirst() pollLast() removeFirst() removeLast()
        //修改
        //查看
        //element() getFirst() getLast() indexOf() LastIndexOf() peek()  peekFirst() peekLast()
        //判断
        //创建LinkedList()
        LinkedList<String> list = new LinkedList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("b");
        list.add("c");
        list.add("e");
        System.out.println(list);
        list.addFirst("ffffff");
        list.addLast("LLLLL");
        System.out.println(list);
        list.offer("oooo");
        list.offerFirst("oooofffff");
        list.offerLast("oooolllll");
        System.out.println(list);
        list.removeFirst();
        System.out.println(list);
        list.removeLast();
        //removeFirst()和removeLast()没有该元素会报错
        //pollFirst和pollLast()没有直接返回NULL更加友好(jdk1.6开始)
        System.out.println(list);
        list.remove(4);
        System.out.println(list);
//        list.clear();
//        System.out.println(list);

        //遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();

        for (String s:list
             ) {
            System.out.print(s+" ");
        }
        System.out.println();
//        Iterator<String> iterator = list.iterator();
//        while (iterator.hasNext()){
//            System.out.print(iterator.next());
//        }
//        System.out.println();
        //节省内存,it在for循环结束就消失
        for (Iterator<String> iterator = list.iterator(); iterator.hasNext();System.out.print(iterator.next()+" "));


        
    }
}
